home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / fat.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-04  |  7.5 KB  |  152 lines

  1. /*
  2.  
  3.     File: fat.h
  4.  
  5.     Copyright (C) 1998-2004 Christophe GRENIER <grenier@cgsecurity.org>
  6.   
  7.     This software is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.   
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.   
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  */
  22.  
  23. #ifndef FAT_H
  24. #define FAT_H
  25. #define FAT1X_PART_NAME 0x2B
  26. #define FAT32_PART_NAME 0x47
  27. #define FAT_NAME1       0x36
  28. #define FAT_NAME2       0x52    /* FAT32 only */
  29. #define NTFS_NAME       0x03
  30. #define OS2_NAME        0x03
  31.  
  32. #define NBR_SECT        8
  33.  
  34. /*
  35.  * FAT partition boot sector information, taken from the Linux
  36.  * kernel sources.
  37.  */
  38.  
  39. struct fat_boot_sector {
  40.     __u8    ignored[3];    /* 0x00 Boot strap short or near jump */
  41.     __s8    system_id[8];    /* 0x03 Name - can be used to special case
  42.                    partition manager volumes */
  43.     __u8    sector_size[2];    /* 0x0B bytes per logical sector */
  44.     __u8    cluster_size;    /* 0x0D sectors/cluster */
  45.     __u16    reserved;    /* 0x0E reserved sectors */
  46.     __u8    fats;        /* 0x10 number of FATs */
  47.     __u8    dir_entries[2];    /* 0x11 root directory entries */
  48.     __u8    sectors[2];    /* 0x13 number of sectors */
  49.     __u8    media;        /* 0x15 media code (unused) */
  50.     __u16    fat_length;    /* 0x16 sectors/FAT */
  51.     __u16    secs_track;    /* 0x18 sectors per track */
  52.     __u16    heads;        /* 0x1A number of heads */
  53.     __u32    hidden;        /* 0x1C hidden sectors (unused) */
  54.     __u32    total_sect;    /* 0x20 number of sectors (if sectors == 0) */
  55.  
  56.     /* The following fields are only used by FAT32 */
  57.     __u32    fat32_length;    /* 0x24=36 sectors/FAT */
  58.     __u16    flags;        /* 0x28 bit 8: fat mirroring, low 4: active fat */
  59.     __u8    version[2];    /* 0x2A major, minor filesystem version */
  60.     __u32    root_cluster;    /* 0x2C first cluster in root directory */
  61.     __u16    info_sector;    /* 0x30 filesystem info sector */
  62.     __u16    backup_boot;    /* 0x32 backup boot sector */
  63.     __u8    BPB_Reserved[12];    /* 0x34 Unused */
  64.     __u8    BS_DrvNum;        /* 0x40 */
  65.     __u8    BS_Reserved1;        /* 0x41 */
  66.     __u8    BS_BootSig;        /* 0x42 */
  67.     __u8    BS_VolID[4];        /* 0x43 */
  68.     __u8    BS_VolLab[11];        /* 0x47 */
  69.     __u8    BS_FilSysType[8];    /* 0x52=82*/
  70.  
  71.     /* */
  72.     __u8    nothing[420];    /* 0x5A */
  73.     __u16    marker;
  74. } __attribute__ ((__packed__));
  75.  
  76. struct msdos_dir_entry {
  77.     __s8    name[8],ext[3];    /* name and extension */
  78.     __u8    attr;        /* attribute bits */
  79.     __u8    lcase;        /* Case for base and extension */
  80.     __u8    ctime_ms;    /* Creation time, milliseconds */
  81.     __u16    ctime;        /* Creation time */
  82.     __u16    cdate;        /* Creation date */
  83.     __u16    adate;        /* Last access date */
  84.     __u16   starthi;    /* High 16 bits of cluster in FAT32 */
  85.     __u16    time,date,start;/* time, date and first cluster */
  86.     __u32    size;        /* file size (in bytes) */
  87. };
  88.  
  89. /* Up to 13 characters of the name */
  90. struct msdos_dir_slot {
  91.     __u8    id;        /* 00 sequence number for slot */
  92.     __u8    name0_4[10];    /* 01 first 5 characters in name */
  93.     __u8    attr;        /* 0B attribute byte */
  94.     __u8    reserved;    /* 0C always 0 */
  95.     __u8    alias_checksum;    /* 0D checksum for 8.3 alias */
  96.     __u8    name5_10[12];    /* 0E 6 more characters in name */
  97.     __u16   start;        /* starting cluster number, 0 in long slots */
  98.     __u8    name11_12[4];    /* last 2 characters in name */
  99. };
  100.  
  101.  
  102. int check_FAT(t_param_disk *disk_car,t_diskext *partition, const int debug);
  103. int test_FAT(t_param_disk *disk_car,const struct fat_boot_sector *fat_header, t_diskext *partition,const int debug, const int dump_ind);
  104. int comp_FAT(t_param_disk *disk_car,const t_diskext *partition, const dword taille, const dword sect_res);
  105. unsigned int get_frag(const unsigned char *buffer, const int fat_type);
  106. int dump_fat_rapport(const struct fat_boot_sector*fh1, const upart_type_t upart_type);
  107. int dump_2fat_rapport(const struct fat_boot_sector*fh1, const struct fat_boot_sector*fh2, const upart_type_t upart_type);
  108. int sort_fat(int pos_fat_test, int debug);
  109. int search_fat_aux(t_param_disk *disk_car,const t_diskext *partition,const dword max_offset,const int p_fat12,const int p_fat16,const int p_fat32,int *f_fat12,int*f_fat16,int*f_fat32,const int debug,const int dump_ind,const int interface);
  110.  
  111. dword get_subdirectory(t_param_disk *disk_car,const dword hd_offset, const dword i);
  112. dword get_next_cluster(t_param_disk *disk_car,const t_diskext *partition, const upart_type_t upart_type,const int offset, dword cluster);
  113. dword get_prev_cluster(t_param_disk *disk_car,const t_diskext *partition, const upart_type_t upart_type,const int offset, const dword cluster, const dword no_of_cluster);
  114. int recover_FAT12(t_param_disk *disk_car,const struct fat_boot_sector*fat_header, t_diskext *partition, const int debug, const int dump_ind);
  115. int recover_FAT16(t_param_disk *disk_car,const struct fat_boot_sector*fat_header, t_diskext *partition, const int debug, const int dump_ind);
  116. int recover_FAT32(t_param_disk *disk_car,const struct fat_boot_sector*fat_header, t_diskext *partition, const int debug, const int dump_ind, const int backup);
  117. int recover_HPFS(t_param_disk *disk_car, const struct fat_boot_sector*fat_header, t_diskext *partition, const int debug, const int dump_ind);
  118. int recover_OS2MB(t_param_disk *disk_car, const struct fat_boot_sector*fat_header, t_diskext *partition, const int debug, const int dump_ind);
  119. int is_fat(const int part_type);
  120. int is_fat12(const int part_type);
  121. int is_fat16(const int part_type);
  122. int is_fat32(const int part_type);
  123. int dir_partition_fat(WINDOW *window,t_param_disk *disk_car, t_diskext *partition, const int debug);
  124. unsigned int get_dir_entries(const struct fat_boot_sector *fat_header);
  125. int dump_fat_info(const struct fat_boot_sector*fh1, const upart_type_t upart_type);
  126. int dump_2fat_info(const struct fat_boot_sector*fh1, const struct fat_boot_sector*fh2, const upart_type_t upart_type);
  127. int dump_fat_info_rapport(const struct fat_boot_sector*fh1, const upart_type_t upart_type);
  128. int fat32_set_part_name(t_param_disk *disk_car, t_diskext *partition, const struct fat_boot_sector*fat_header);
  129. unsigned int sector_size(const struct fat_boot_sector *fat_header);
  130. unsigned int sectors(const struct fat_boot_sector *fat_header);
  131. dword fat32_get_prev_cluster(t_param_disk *disk_car,const t_diskext *partition, const unsigned int fat_offset, const dword cluster, const dword no_of_cluster);
  132. int fat32_free_info(t_param_disk *disk_car,const t_diskext *partition, const unsigned int fat_offset, const dword no_of_cluster,dword *next_free,dword*free_count);
  133. dword get_free_count(const unsigned char *boot_fat32);
  134. dword get_next_free(const unsigned char *boot_fat32);
  135.  
  136. #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
  137. #define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG)
  138. #define ATTR_RO      1  /* read-only */
  139. #define ATTR_HIDDEN  2  /* hidden */
  140. #define ATTR_SYS     4  /* system */
  141. #define ATTR_VOLUME  8  /* volume label */
  142. #define ATTR_DIR     16 /* directory */
  143. #define ATTR_ARCH    32 /* archived */
  144.  
  145. #define ATTR_NONE    0 /* no attribute bits */
  146. #define ATTR_UNUSED  (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
  147.     /* attribute bits that are copied "as is" */
  148. #define ATTR_EXT     (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
  149. #define ATTR_EXT_MASK     (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME | ATTR_DIR | ATTR_ARCH)
  150.     /* bits that are used by the Windows 95/Windows NT extended FAT */
  151. #endif
  152.